package mo.leetcode_hot;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class L1 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> num2index = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            num2index.put(nums[i], i);
        }
        for (int i = 0; i < nums.length; i++) {
            Integer pair = num2index.get(target - nums[i]);
            if (pair != null && pair != i) {
                return new int[]{i, pair};
            }
        }
        return new int[]{-1, -1};
    }

    public static void main(String[] args) {
        L1 test = new L1();
        System.out.println(Arrays.toString(test.twoSum(new int[]{3, 2, 4}, 6)));
    }
}
